'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-04-07 10:26:05
'''
#nohup python -u deal_all.py > all_result 2>&1 &
import math
import sys

import direct_deal
# 0 工作日上午 1 工作日下午 2 周末上午 3 周末下午
# dates = ["2020-03-09", "2020-03-10", "2020-03-11", "2020-03-12", "2020-03-13"]
#dates[0]工作日， dates[1]周末
dates = [["2020-08-24", "2020-08-25", "2020-08-26", "2020-08-27", "2020-08-28"], ["2020-08-29", "2020-08-30"]]
# out_date = sys.argv[1]


out_path = "./cp_active_time" #更改文件
for i, date_ in enumerate(dates):
    time_dict = {}
    num_dict = {}
    for j, a_p in enumerate(['am', 'pm']):
        for date in date_:
            path = date + "/boss_cp_geek_active_time_" + a_p
        #    path = date + "/boss_cp_exp_active_time_pm"
            print(path)
            with open(path, 'r') as f:
                for line in f:
                    lineArr = line.split('\t')
                    cp = lineArr[0] + '\t' + lineArr[1]
                    at = int(lineArr[2])
                    if cp in time_dict:
                        time_dict[cp] += at
                    else:
                        time_dict[cp] = at
                    if cp in num_dict:
                        num_dict[cp] += 1
                    else:
                        num_dict[cp] = 1

        print(len(time_dict))
        print(len(num_dict))

        
        out = open(out_path, 'a+')

        for k, v in time_dict.items():
            at = v / float(num_dict[k])
            interval = (int(math.ceil(float(at))))
        #    print num_dict[k]
        #    print interval
            out.write(k + '\t' + str(interval) + '\t' + str(2*i+j) + '\n')

        out.close()